
using Youz.Common.DBUtility;
using Youz.Common.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.Common.DAL
{
    /// <summary>
    /// Log_OperationLog Data Class
    /// </summary>
    public partial class Log_OperationLogDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Log_OperationLog";

        public Log_OperationLogDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Log_OperationLog model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Log_OperationLog](");
            strSql.Append("[OperationID],[MemberAccount],[ModuleName],[FunctionName],[URI],[PostData],[OperationContent],[CreateTime],[LoginID],[LoginType],[Sensitive],[OperatingDetails]");
            strSql.Append(") values (");
            strSql.Append("@OperationID,@MemberAccount,@ModuleName,@FunctionName,@URI,@PostData,@OperationContent,@CreateTime,@LoginID,@LoginType,@Sensitive,@OperatingDetails");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@OperationID", model.OperationID),
                    new SqlParameter("@MemberAccount", model.MemberAccount),
                    new SqlParameter("@ModuleName", model.ModuleName),
                    new SqlParameter("@FunctionName", model.FunctionName),
                    new SqlParameter("@URI", model.URI),
                    new SqlParameter("@PostData", model.PostData),
                    new SqlParameter("@OperationContent", model.OperationContent),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@LoginID", model.LoginID),
                    new SqlParameter("@LoginType", model.LoginType),
                    new SqlParameter("@Sensitive", model.Sensitive),
                    new SqlParameter("@OperatingDetails", model.OperatingDetails)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Log_OperationLog model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Log_OperationLog] set ");
            strSql.Append("[MemberAccount]=@MemberAccount,[ModuleName]=@ModuleName,[FunctionName]=@FunctionName,[URI]=@URI,[PostData]=@PostData,[OperationContent]=@OperationContent,[CreateTime]=@CreateTime,[LoginID]=@LoginID,[LoginType]=@LoginType,[Sensitive]=@Sensitive,[OperatingDetails]=@OperatingDetails");
            strSql.Append(" where [OperationID]=@OperationID");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@OperationID", model.OperationID),
                    new SqlParameter("@MemberAccount", model.MemberAccount),
                    new SqlParameter("@ModuleName", model.ModuleName),
                    new SqlParameter("@FunctionName", model.FunctionName),
                    new SqlParameter("@URI", model.URI),
                    new SqlParameter("@PostData", model.PostData),
                    new SqlParameter("@OperationContent", model.OperationContent),
                    new SqlParameter("@CreateTime", model.CreateTime),
                    new SqlParameter("@LoginID", model.LoginID),
                    new SqlParameter("@LoginType", model.LoginType),
                    new SqlParameter("@Sensitive", model.Sensitive),
                    new SqlParameter("@OperatingDetails", model.OperatingDetails)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid OperationID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Log_OperationLog] ");
            strSql.Append(" where [OperationID]=@OperationID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@OperationID", OperationID)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Log_OperationLog Get(Guid OperationID)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Log_OperationLog] ");
            strSql.Append(" where [OperationID]=@OperationID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("OperationID", OperationID)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Log_OperationLog Get(DataRow row)
        {
            if (row == null) return null;

            Log_OperationLog model = new Log_OperationLog();
	
            
            if (row["OperationID"] != DBNull.Value)
            {
                model.OperationID = (Guid)row["OperationID"];
            }      
            
            if (row["MemberAccount"] != DBNull.Value)
            {
                model.MemberAccount = (String)row["MemberAccount"];
            }      
            
            if (row["ModuleName"] != DBNull.Value)
            {
                model.ModuleName = (String)row["ModuleName"];
            }      
            
            if (row["FunctionName"] != DBNull.Value)
            {
                model.FunctionName = (String)row["FunctionName"];
            }      
            
            if (row["URI"] != DBNull.Value)
            {
                model.URI = (String)row["URI"];
            }      
            
            if (row["PostData"] != DBNull.Value)
            {
                model.PostData = (String)row["PostData"];
            }      
            
            if (row["OperationContent"] != DBNull.Value)
            {
                model.OperationContent = (String)row["OperationContent"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            
            if (row["LoginID"] != DBNull.Value)
            {
                model.LoginID = (Guid)row["LoginID"];
            }      
            
            if (row["LoginType"] != DBNull.Value)
            {
                model.LoginType = (Int32)row["LoginType"];
            }

            if (row["Sensitive"] != DBNull.Value)
            {
                model.Sensitive = (Int32)row["Sensitive"];
            }

            if (row["OperatingDetails"] != DBNull.Value)
            {
                model.OperatingDetails = (String)row["OperatingDetails"];
            }  

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Log_OperationLog] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Log_OperationLog] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Log_OperationLog] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Log_OperationLog]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by CreateTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }
        /// <summary>
        /// 敏感操作记录
        /// </summary>
        /// <param name="sqlWhere"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="total"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable GetsSensitive(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT a.*,b.[LoginIP] FROM [Log_OperationLog] a Left join [dbo].[Log_LoginLog] b on a.LoginID = b.LoginID ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by CreateTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法
    }
}


  